package com.shenyue.nbtownlet.util;


import java.security.MessageDigest;

public class MD5Util {
    public static String byte2hex(byte[] paramArrayOfByte) {
        StringBuffer localStringBuffer = new StringBuffer();
        for (int i = 0; i < paramArrayOfByte.length; ++i)
            localStringBuffer.append(Integer
                    .toHexString(256 + (paramArrayOfByte[i] & 0xFF))
                    .substring(1).toUpperCase());
        return localStringBuffer.toString();
    }

    public static String md5(String origin, String charsetname) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            return byte2hex(md.digest(origin.getBytes(charsetname)));
        } catch (Exception e) {
            return null;
        }
    }

    public static String md5(String origin) {
        return md5(origin, "utf8");
    }
}
